<script language="php">

session_start();

if (!isset($_SESSION['userlogin'])) 
{
	header("Location:index.php");
}


function buildQuery($player,$row,$column,$team,$queryID)
{
// adapted from /http://www.willfitch.com/simplexml-tutorial-part1.html
  $xml = new SimpleXMLElement('<captureQuery></captureQuery>');
  $make = $xml->addChild('code',2);
  $make = $xml->addChild('user',$player);
  $make = $xml->addChild('team',$team);
  $make = $xml->addChild('timestamp',time());
  $make = $xml->addChild('row',$row);
  $make = $xml->addChild('column',$column);
  $make = $xml->addChild('queryID',$queryID);

  $xml->asXML('xmlqueries/query'.$queryID.'.xml');
}

//adapted from http://www.developertutorials.com/tutorials/php/php-hit-counter-050620-1087/
//get the query number to give unqiue ID
$buildQueryCounter= "xmlqueries/querycounter.txt" ;
$fhandler = fopen ($buildQueryCounter , "r") or die ("Can't open $buildQueryCounter") ;
$fstring = fread ($fhandler , filesize ($buildQueryCounter)) ;
echo "$fstring" ;
fclose($fhandler) ;

//update query counter
$player = $_SESSION['userlogin'];
$row = $_POST['row'];
$column = $_POST['column'];
$team = $_SESSION['team'];

buildQuery($player,$row,$column,$team,$fstring);

$fhandler = fopen ($buildQueryCounter , "w") or die ("Can't open $buildQueryCounter") ;
$fcounted = $fstring + 1 ;
$fout= fwrite ($fhandler , $fcounted ) ;
fclose($fhandler) ;

</script>